<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 青蛙过河 -->
    <script>
      var canCross = function (stones) {
        let len = stones.length
        let dp = new Array(len)
        for (let i = 0; i < len; i++) {
          dp[i] = new Array(len + 1).fill(0)
        }
        dp[0][0] = true
        if (stones[1] > 1) return false

        for (let i = 0; i < len; i++) {
          for (let j = 0; j < i; j++) {
            let k = stones[i] - stones[j]
            dp[i][k] = dp[j][k - 1] || dp[j][k] || dp[j][k + 1]
            if (i == len - 1 && dp[i][k]) {
              return true
            }
          }
        }
        return false
      }
      console.log(canCross([0, 1, 3, 5, 6, 8, 12, 17]))
    </script>
  </body>
</html>
